===========================================================================
==  Simple GUI's for beginners with AmigaDos 3          By:  Paul Moore  ==
===========================================================================

You may not think you're cut out for programming on the Amiga, but it's
amazing what you can do with a little help from a couple of new commands
present with Amigados 3 and above. 

Okay, you're not going to be able to produce that masterpiece you've always
dreamed of, but you could improve on a few of those shell-based programs
that you use, cutting down on the time spent typing and remembering all the
commands you need.

Here's an example.  If you use the archiver lha from the shell, to extract
a file you might need to type in the following:

lha x work:downloads/ar301.lha work:files/magazines/ar

A bit of a hassle, I'm sure you'll agree.  All this could be eliminated
with a little knowledge of the commands RequestChoice and RequestFile in
your c: drawer.

Let's look at a more simple example.  To view a text file with Commodore's
included 'more' program, you need to open a shell and type in something
like 'more work:files/text/myfile.doc'.  Using RequestFile we'll make an
interface that will allow you to select the file you want from a standard
file requester.

First we need to look at what parameters you need to know.  In this case,
it is simply the name of the file you want to view.  This is held in a
string, which you give a name such as $textfile.  For convenience we will
store this string in the RAM:env drawer.

Okay, here's the script, it is pretty simple but it'll show you the basics
of RequestFile.  You simply type this up as a text file in your favourite
text editor, and save it as plain ASCII text.  I have numbered the lines
below to illustrate points, you would not do this when creating your own
script.

1  ; Simple requester front-end for More                   
2  ; By Paul Moore, 1995                                   
3  C:RequestFile >env:textfile TITLE "Which text file?"    
4  more $textfile                                          
5  ; That's it!                                            


Lines 1,2 and 5 are what are known as comment lines.  These allow you to
make any remarks to yourself or others in your script for later
examination.  They are preceded in the case of AmigaDos scripts by ';'. 
Arexx and C use /* and */ for comments.

Line 3 is where RequestFile comes into action.  This produces a requester
which allows you to select a file.  The file and it's whereabouts on your
hard disk are stored in the string 'textfile'.  The 'TITLE' option allows
you to add your own title to the requester.

Line 4 is the same as the command you'd have to type in if entering the
location from the shell (like `more work:myfile.txt') except that the
string 'textfile' is used.  The file will be displayed as normal, but you
won't have to type in the location of the file every time you run the
script, unlike using More manually from the shell. 

Type the above lines into a text editor and save them (without line
numbers!) as ASCII text.  You can test the script by typing

execute (location of script) eg execute work:myscript

We'll look into making the script run on it's own later.

Right.  Now we'll make it a bit more complex and use the command
RequestChoice.  This creates a requester with buttons, like the
Retry/Cancel requesters you often come across. 

For our second script we'll keep the text viewer part from the first
script, but add the facility to edit a text file using 'Ed' the editor that
comes with your amiga.

We want to have the choice of either editing or viewing a file, so we
create a simple button choice with RequestChoice.  Requestchoice uses a
similar format to Requestfile; here's the line we need to start it:

C:requestchoice >env:operation "Paul's Script" "Choose the operation you
want to carry out" "View" "Edit" "Quit"

This should be all on one line.

The first part takes in the operation string.  This is followed in
quotation marks by a heading for the window.  Then a sub heading for inside
the window, and then by the three buttons, "View", "Edit" and "Quit". 

The two operations, view and edit, we'll make into two seperate procedures,
or operations.  These are given names with LAB.  There is a procedure for
staring off, for viewing and for editing.  LAB seperates each part. 

Now we need to make a decision.  With RequestChoice this is by assigning
numbers to each button and deciding IF it is one statement or the other.  
The number 0 is always for the last option, Quit.  1, 2 and so on are used
from left to right for the other options so in our case, 1 is "View" and 2
is "Edit".  This is how it looks in the script:

if $operation eq "0"
C:endcli
endif
if $operation eq "1"
skip view
endif
if $operation eq "2"
skip edit
endif

So let's now look at how the entire script comes together;

; Simple GUI to allow you to select to view or edit a text file.
; By Paul Moore, 1995

LAB start
C:requestchoice >env:operation "Paul's Script" "Choose the operation you
  want to carry out" "View" "Edit" "Quit"
if $operation eq "0"
C:endcli
endif
if $operation eq "1"
skip view
endif
if $operation eq "2"
skip edit
endif
;
; This is the procedure for viewing the text file with More
LAB view
C:RequestFile >env:textfile TITLE "Which text file?"
more $textfile
C:endcli
;; This is the procedure for loading Ed to edit a text file
LAB edit
C:RequestFile >env:editfile TITLE "Which text file?"  
ed $editfile
c:endcli

Instead of having to type 'execute' and the filename to run it every time
there are two ways of making your scripts executable or, self-running.  The
first is to create an icon for it with any icon editor and save it as a
Project type icon.  Then using the 'Information...' option in the Icon menu
on Workbench, change the default tool to IconX and select Save.  Now you
can run your program by double clicking on the icon.

The second method is to use the 'protect' command.  Type something similar
to the following:

Protect work:myscript +s

You can now run the script by simply typing in its name.

It's a simple as that.  So what else could you do with similar scripts?
You could create a GUI front-end for Lha (an option to extract,add or list
archives created with RequestChoice followed by file handling with
RequestFile), or how about a program to allow you to select which of your
favourite programs to load from a series of buttons, using RequestChoice? 
You could use it to simplify tasks like converting sound samples to
different formats with AmiSox or make a nice front end for BigAnim.  The
choice is yours!


converted with guide2html by Kochtopf